import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hello/douban/modal/home.dart';
import 'package:hello/douban/pages/home/local_host.dart';
import 'package:hello/douban/widgets/dashed_line.dart';
import 'package:hello/douban/widgets/star_rating.dart';

class HomeMovieItem extends StatelessWidget {
  final MovieItem _movie;
  final int index;

  HomeMovieItem(this._movie,this.index);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(8),
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(
            width: 8,
            color: Color(0xffaaaaaa),
          )
        )
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          buildHeader(),
          SizedBox(height: 8,),
          buildContent(),
          SizedBox(height: 8,),
          buildFooter(),
        ],
      ),
    );
  }
  // 头部布局
  buildHeader(){
    return Container(
      padding: EdgeInsets.fromLTRB(10, 5, 10, 5),
      decoration: BoxDecoration(
        color: Color.fromARGB(255, 238, 205, 144),
        borderRadius: BorderRadius.circular(3)
      ),
      child: Text("No.${index + 1}",style: TextStyle(fontSize: 18),),
    );
  }
//  内容布局
  buildContent(){
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        buildContentImage(),
        SizedBox(width: 9,),
        buildContentInfo(),
        SizedBox(width: 9,),
        buildContentInfoLine(),
        SizedBox(width: 9,),
        buildContentWish()
      ],
    );
  }
//  
  buildContentImage(){
    return ClipRRect(
      borderRadius: BorderRadius.circular(8),
      child: Image.network(_movie.cover,height: 150,),
    );
  }
  
  buildContentInfo(){
    return Expanded(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          buildContentInfoTitle(),
          SizedBox(height: 8,),
          buildContentInfoRate(),
          SizedBox(height: 8,),
          buildContentInfoDesc()
        ],
      ),
    );
  }
  buildContentInfoTitle(){
    return Text.rich(
      TextSpan(
        children: [
          WidgetSpan(child:
          Icon(Icons.play_circle_outline,color: Colors.redAccent,size: 24,),),
          TextSpan(
            text:_movie.title,
            style: TextStyle(fontSize: 18,fontWeight: FontWeight.bold),
          ),
          TextSpan(
            text: "(上映年份)",
            style: TextStyle(color: Color(0xffaaaaaa),fontSize: 14)
          )
        ],
      )
    );
  }
  buildContentInfoRate(){
    return Row(
      children: [
        LJStarRating(rating: double.parse(_movie.rate),size: 20,),
        Text(_movie.rate)
      ],
    );
  }
  buildContentInfoDesc(){
    return Text("$plot / $directors / $actors",
      maxLines: 2,
      overflow: TextOverflow.ellipsis,
    );
  }
  buildContentInfoLine(){
    return Container(
      height: 120,
      child: HYDashedLine(
        axis: Axis.vertical,
        dashedWidth: 1,
        dashedHeight: 6,
        count: 10,
        color: Colors.red,
      ),
    );
  }
  buildContentWish(){
    return Container(
      height: 100,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Image.asset("assets/images/home/wish.png",width: 30,),
          Text("想看",style: TextStyle(color: Color.fromARGB(255, 235, 170, 60),fontSize: 18,
          fontWeight: FontWeight.bold
          ),)
        ],
      ),
    );
  }
  buildFooter(){
    return Container(
      height: 40,
      width: double.infinity,
      decoration: BoxDecoration(
        color: Color(0xffe2e2e2),
        borderRadius: BorderRadius.circular(6),
      ),
      alignment: Alignment(-1,0),
      child:Text("原始名字")
    );
  }
}
